#!/bin/bash
IFS=$'\n'
res=$(find $PWD -name "*.md" -print0 | xargs -0 ls)

for file in $res; do
   echo "file=\"$file\""
   dir=$(dirname \"$file\")
   dir_name=$(basename \"$dir\")
   #echo "dir=$dir dir_name=$dir_name"
   echo "---" > temp.md
   echo "title: $(basename $file .md)" >> temp.md
   echo "aliases:" >> temp.md
   echo "tags: [$dir_name]" >> temp.md

   date="`ls --full-time $file | cut -d ' ' -f 6`"
   time="`ls --full-time $file | cut -d ' ' -f 7`"


   echo "date: $date $time" >> temp.md
   echo "---" >> temp.md
    cat "$file" >> temp.md
    mv temp.md "$file"
done
